package cn.sczhyt.modules.szhy.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.sczhyt.modules.szhy.entity.MeetingTopicsFileEntity;
import cn.sczhyt.modules.szhy.service.MeetingTopicsFileService;
import cn.sczhyt.common.utils.PageUtils;
import cn.sczhyt.common.utils.R;
import org.springframework.web.multipart.MultipartFile;


/**
 * 议题文件
 *
 * @author luojialin
 * @email 78357966@qq.com
 * @date 2021-05-18 10:39:50
 */
@Api(tags = "PC端议题文件")
@RestController
@RequestMapping("szhy/meetingtopicsfile")
public class MeetingTopicsFileController {
    @Autowired
    private MeetingTopicsFileService meetingTopicsFileService;

    /**
     * 列表
     */
    @ApiOperation("获取议题文件列表")
    @RequestMapping("/list/{topicsId}")
    public R list(@PathVariable("topicsId") String topicsId){
        QueryWrapper<MeetingTopicsFileEntity> queryWrapper = new QueryWrapper<>();
        List<MeetingTopicsFileEntity> list = meetingTopicsFileService.list(queryWrapper.eq("topics_id", topicsId));

        return R.ok().put("data", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		MeetingTopicsFileEntity meetingTopicsFile = meetingTopicsFileService.getById(id);

        return R.ok().put("meetingTopicsFile", meetingTopicsFile);
    }

    /**
     * 保存
     */
    @ApiOperation("保存议题文件")
    @PostMapping("/save")
    public R save(@RequestParam("file") MultipartFile[] files, @RequestParam String topicsId){

        meetingTopicsFileService.saveTopicsFile(files,topicsId);

        return R.ok();

    }


    /**
     * 修改
     */
    @ApiOperation("修改议题文件")
    @RequestMapping("/update")
    public R update(@RequestBody MeetingTopicsFileEntity meetingTopicsFile){
		meetingTopicsFileService.updateById(meetingTopicsFile);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("删除议题文件")
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids){
		meetingTopicsFileService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
